package com.heima.article.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.article.mapper.ArticleContentMapper;
import com.heima.article.mapper.RecommendMapper;
import com.heima.article.service.ApArticleService;
import com.heima.article.service.ArticleContentService;
import com.heima.article.service.ArticleRecommendService;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.article.pojos.ArticleContent;
import com.heima.model.article.pojos.Recommend;
import com.heima.model.article.vos.ApArticleContentVo;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName ArticleRecommendServiceImpl
 * @Description TODO
 * @Author Neo
 * @Date 2024/3/9 20:43
 * @Version 1.0
 */
@Component
public class ArticleContentServiceImpl extends ServiceImpl<ArticleContentMapper, ArticleContent> implements ArticleContentService {

    @Autowired
    private ApArticleService apArticleService;
    @Override
    public ResponseResult getContent(Long articleId) {

        ApArticle byId = apArticleService.getById(articleId);
        QueryWrapper<ArticleContent> articleContentQueryWrapper = new QueryWrapper<>();
        articleContentQueryWrapper.eq("article_id",articleId);
        ArticleContent one = getOne(articleContentQueryWrapper);
        if(one!=null&&byId!=null){
            ApArticleContentVo apArticleContentVo = new ApArticleContentVo();
            BeanUtils.copyProperties(one,apArticleContentVo);

            apArticleContentVo.setAuthorName(byId.getAuthorName());
            apArticleContentVo.setTitle(byId.getTitle());
            return ResponseResult.okResult(apArticleContentVo);
        }
        return null;
    }
}
